<template>
  <div class="goods-list-container">
    <MyHeader :title="title"></MyHeader>
    <MyTable :list="list">
      <template #header>
        <th>#</th>
        <th>商品名称</th>
        <th>价格</th>
        <th>标签</th>
        <th>操作</th>
      </template>
      <template #body="scope">
        <td>
          {{ scope.row.id }}
        </td>
        <td>
          {{ scope.row.goods_name }}
        </td>
        <td>
          {{ scope.row.goods_price }}
        </td>
        <td>
          <span
            v-for="(str, index) in scope.row.tags"
            :key="index"
            class="badge bg-warning"
          >
            {{ str }}
          </span>
        </td>
        <td>
          <button @click="del(scope.row.id)" class="btn btn-sm btn-danger">
            删除
          </button>
        </td>
      </template>
    </MyTable>
  </div>
</template>

<script>
import MyHeader from "../components/MyHeader.vue";
import MyTable from "../components/MyTable.vue";

export default {
  components: {
    MyHeader,
    MyTable,
  },
  data() {
    return {
      title: "商品列表页",
      list: [],
    };
  },
  async created() {
    let res = await this.$axios({
      url: "/api/goods",
    });

    this.list = res.data.data;
  },

  mounted() {},

  methods: {
    del(id) {
      let index = this.list.findIndex((item) => item.id == id);
      this.list.splice(index, 1);
    },
  },
};
</script>

<style lang="less" scoped>
.goods-list-container {
  padding-top: 45px;
}

.badge {
  margin-right: 5px;
}
</style>